// JavaScript Document
var sliderTimeOut;
var sliderCurIndex;
var slideChanging = false;
$(document).ready(function () {
    createSlider();
});

function createSlider() {
    $(".slider .slider_image").hide();
    sliderCurIndex = 0;
    sliderChangePic();
	
    $(".slider").mouseenter(function (e) {
        $(this).children(".slider_tooltip").fadeIn("fast");
        $(this).children(".slider_button").show();
    });
    $(".slider").mouseleave(function (e) {
        $(this).children(".slider_tooltip").stop();
        $(this).children(".slider_tooltip").fadeOut("fast");
        $(this).children(".slider_button").hide();
    });
    $(".slider").load("script", function () {
        //var sliderwidth = $(this).width();
        var sliderheight = $(this).height();
        //var buttonwidth = $(this).width();
        var buttonheight = $(this).children(".slider_button").height();
        $(this).children(".slider_button").css("top", (sliderheight / 2) - (buttonheight / 2));
        $(this).children(".slider_prevpic").css("left", 15);
        $(this).children(".slider_nextpic").css("right", 15);
    });
    $(".slider .slider_nextpic").click(function (e) {
        if (!slideChanging) {
            sliderChangePic();
        }
    });
    $(".slider .slider_prevpic").click(function (e) {
        if (!slideChanging) {
            sliderCurIndex = ($(".slider .slider_image").size() + sliderCurIndex - 2) % $(".slider .slider_image").size();
            sliderChangePic();
        }
    });
}

function sliderChangePic() {
    if (!slideChanging) {
        slideChanging = true;
        if (sliderTimeOut != null) {
            clearTimeout(sliderTimeOut);
            sliderTimeOut = null;
        }
        $(".slider .slider_image").fadeOut(1000);
        var img = $(".slider .slider_image:eq(" + sliderCurIndex + ")").children("img");
        $(".slider .slider_picname").text(img.attr("imgname"));
        $(".slider .slider_picauthor").text(img.attr("imgauthor"));
        $(".slider .slider_picdate").text(img.attr("imgdate"));
        $(".slider .slider_picdesc").text(img.attr("imgdescription"));
		$(".slider .slider_image:eq(" + sliderCurIndex + ")").fadeIn(1000, function () {
            sliderCurIndex++;
            if ($(".slider .slider_image").size() <= sliderCurIndex) {
                if (sliderCurIndex == 1) {
                    return false;
                }
                sliderCurIndex = 0;
            }
            sliderTimeOut = setTimeout("sliderChangePic()", 5000);
            slideChanging = false;
        });
    } 
}
